
Option Speed 7

Button 1 Text Mot1_90
Button 2 Text Mot1_500
Button 3 Text Mot2_100
Button 4 Text Mot2_700
Button 5 Text Mot12_111_222
Stop

Label Mot1_90
	v1 = 90			' Destinazione per motore 1
	v2 = 5			' Velocit? (da 0.01 a 10)
	Gosub Muovi1		' Muovi motore 1
Stop

Label Mot1_500
	v1 = 500		' Destinazione per motore 1
	v2 = 5			' Velocit? (da 0.01 a 10)
	Gosub Muovi1	' Muovi motore 1
Stop

Label Mot2_100
	v1 = 100		' Destinazione per motore 1
	v2 = 5			' Velocit? (da 0.01 a 10)
	Gosub Muovi2	' Muovi motore 1
Stop

Label Mot2_700
	v1 = 700		' Destinazione per motore 1
	v2 = 5			' Velocit? (da 0.01 a 10)
	Gosub Muovi2	' Muovi motore 1
Stop

Label Mot12_111_222
	v1 = 111		' Destinazione per motore 1
	v2 = 222		' Destinazione per motore 2
	v3 = 5			' Velocit? mot 1 (da 0.01 a 10)
	v4 = 5			' Velocit? mot 2 (da 0.01 a 10)
	Gosub Muovi12	' Muovi motore 1 e 2 contemporaneamente
Stop

Label Muovi1
	v3 = Slot(1)	' Leggo posizione attuale 
	If v3 > v1 		' Se deve scendere allora
		v2 = -v2	'  inverto la velocit?
	EndIf
	Label LoopM1
		v3 = v3 + v2  	' Incremento la posizione
		Slot 1 = v3   	' e la scrivo nel motore 1
		' ----------------------------------------
		' controllo se la destinazione ? raggiunta 
		If (v2 > 0 And v3 > v1) Or (v2 < 0 And v3 < v1)
			Slot 1 = v1 ' Imposto destinazione
			Return      ' e torno
		EndIf
		' ----------------------------------------
	Goto LoopM1
Stop

Label Muovi2
	v3 = Slot(2)	' Leggo posizione attuale 
	If v3 > v1 		' Se deve scendere allora
		v2 = -v2	'  inverto la velocit?
	EndIf
	Label LoopM2
		v3 = v3 + v2  	' Incremento la posizione
		Slot 2 = v3   	' e la scrivo nel motore 1
		' ----------------------------------------
		' controllo se la destinazione ? raggiunta
		If (v2 > 0 And v3 > v1) Or (v2 < 0 And v3 < v1)
			Slot 2 = v1 ' Imposto destinazione
			Return      ' e torno
		EndIf
		' ----------------------------------------
	Goto LoopM2
Stop

Label Muovi12
	v5 = Slot(1)	' Leggo posizione attuale 1
	v6 = Slot(2)	' Leggo posizione attuale 2
	If v5 > v1 		' Se mot1 deve scendere allora
		v3 = -v3	'  inverto la velocit? 1
	EndIf
	If v6 > v2 		' Se mot2 deve scendere allora
		v4 = -v4	'  inverto la velocit? 2
	EndIf
	Label LoopM12
		v5 = v5 + v3  	' Incremento la posizione di mot1
		Slot 1 = v5   	' e la scrivo nel motore 1
		v6 = v6 + v4  	' Incremento la posizione di mot2
		Slot 2 = v6   	' e la scrivo nel motore 2
		' ----------------------------------------
		' controllo se motore 1 ? a destinazione
		If (v3 > 0 And v5 > v1) Or (v3 < 0 And v5 < v1)
			Slot 1 = v1 ' Imposto destinazione
			v5 = v1     ' anche in v5
			v3 = 0      ' e fermo la velocit? di mot1
		EndIf
		' ----------------------------------------
		' controllo se motore 2 ? a destinazione
		If (v4 > 0 And v6 > v2) Or (v4 < 0 And v6 < v2)
			Slot 2 = v2 ' Imposto destinazione
			v6 = v1     ' anche in v6
			v4 = 0      ' e fermo la velocit? di mot2
		EndIf
		' ----------------------------------------
		' controllo se motori 1 e 2 sono fermi
		If v3 = 0 And v4 = 0
			Return      ' e ritorno
		EndIf
	Goto LoopM12
Stop

'WATCH Slot (1)
'WATCH Slot (2)
'WATCH Slot (3)
'WATCH Slot (4)
'WATCH v1
'WATCH v2
'WATCH v3
'WATCH v4
